package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.Agent;
import com.macro.mall.dto.AgentRequest;
import com.macro.mall.service.AgentService;
import com.macro.mall.util.RequestData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author HuangZiy
 * @version 8.0
 * @date 2021/4/26 22:35
 */
@RestController
@RequestMapping(value = "/agent")
public class AgentController {

    @Autowired
    private AgentService agentService;

    @GetMapping("/list")
    public CommonResult<List<Agent>> getAgent(@RequestData AgentRequest request) {
        return agentService.getAgent(request);
    }


    @PostMapping
    public CommonResult<String> addAgent(@RequestBody AgentRequest request) {
        return agentService.addAgent(request);
    }

    @PutMapping("/{id}")
    public CommonResult<String> updateAgent(@PathVariable Integer id, @RequestBody AgentRequest request) {
        request.setId(id);
        return agentService.updateAgent(request);
    }

    @DeleteMapping("/{id}")
    public CommonResult<String> deleteAgent(@PathVariable Integer id) {
        return agentService.deleteAgent(id);
    }


}
